package boogie.game.sound;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Boogie
 */
public final class SoundManager {

    public Map<String, Sound> sounds;
    public Sound nullSound;

    private boolean mute;
    
    private static SoundManager instance;
    
    private SoundManager() {
        sounds = new HashMap<>();
        
    }

    public static SoundManager getInstance(){
        if(instance == null){
            instance = new SoundManager();
        }
        return instance;
    }

    public boolean isMute() {
        return mute;
    }

    public void setMute(boolean mute) {
        this.mute = mute;
    }
        
    
    public void addSound(String name,Sound sound){
        sounds.put(name, sound);        
    }
    public void removeSound(String name){
        if(sounds.containsKey(name)){
            sounds.remove(name);
        }
    }
    public void playSound(String soundName) {
        if (sounds.containsKey(soundName)&&!mute) {
            sounds.get(soundName).play();
        }
    }

    public void loopSound(String soundName) {
        if (sounds.containsKey(soundName)&&!mute) {
            sounds.get(soundName).loop();
        }
    }

    public void stopSound(String soundName) {
        if (sounds.containsKey(soundName)) {
            sounds.get(soundName).stop();
        }
    }
}
